DXL Timer Question

So I have been tinkering around lately with a timer script I came across (I don't remember where I found it but I will update this if I come across it) and was thinking of possibly modifying it to be used with a trigger.

So when a user opens a module in exclusive the timer would start and once it reached it's time limit would then prompt the user if they are still working on the module.

 

I have a semi working version of what I want so far but I just wanted to ask if there is a better way about going at this problem or not.

Also any helpful remarks would be appreciative as well.

 

DB db   = null
DB db2  = null
DBE dbeClock  = null
DBE dbeTime  = null
DBE dbeStart  = null
DBE dbeStop  = null

int interval  = 1
int startTime  = 0
int elapsedTime  = 0

// start the clock
void doStart(DB db)
 {
  Date d  = today
  startTime  = intOf(d)

  //Adjust for any previously elapsed time not reset
  startTime = startTime - elapsedTime
  if (startTimer(dbeClock))
   {
    inactive(dbeStart)
    active(dbeStop)
   }
 }

// stop the clock
void doStop(DB db)
 {
  if (stopTimer(dbeClock))
   {
    active(dbeStart)
    inactive(dbeStop)
   }
 }

// CB on timer updates display
void doClock(DBE dbe)
 {
  Date d   = null

  int currentTime  = null
  int seconds  = 0
  int minutes  = 0
  int hours   = 0
  int days   = 0

  d = today
  currentTime = intOf(d)
  elapsedTime = currentTime - startTime
  seconds  = elapsedTime % 60
  minutes  = (elapsedTime % 3600) / 60
  hours  = (elapsedTime % 86400) / 3600
  days   = elapsedTime / 86400
  string s1  = days " d:" hours " h:" minutes " m:" seconds " s"
  set (dbeTime, s1)
  
  if(seconds == 4)
   {
    //print "Time 1\n\n"

    // reset the clock
    void doReset(DB db)
     {
      elapsedTime  = 0
      string s1   = "0 d:0 h:0 m:0 s"
      set (dbeTime, s1)
      if (stopTimer(dbeClock))
       {
        doStart(db)

        release db2

        hide db2
       }
     }

    // stop the clock
    void doStop(DB db)
     {
      if (stopTimer(dbeClock))
       {
        doReset(db)
        
        save(Module current)

        release db2
        release db

        hide db2
        hide db

        close(Module current)
       }
     }

    db2 = create ("Time Check", styleCentered)
    
    dbeReset  = apply(db2, "Yes",doReset)
    dbeStop  = apply(db2, "No", doStop)

    realize db2

    setCenteredSize(db2, 300, 300)

   }
  else if (seconds == 8)
   {
    save(Module current)

    release db2
    release db

    hide db2
    hide db

    close(Module current)
   }
 }

// reset the clock
void doReset(DB db)
 { 
  elapsedTime  = 0
  string s1   = "0 d:0 h:0 m:0 s"
  set (dbeTime, s1)
  if (stopTimer(dbeClock))
   {
    active(dbeStart)
    inactive(dbeStop)
   }
 }

db   = create(dbExplorer, "Module Timer", styleCentered | styleNoBorder)

dbeTime  = field(db, "Elapsed Time", "", 20, true)
dbeClock  = timer(db, interval, doClock, "")// create the timer.

doStart(db)

dbeStart  = apply(db, "Start",doStart)
dbeStop  = apply(db, "Stop", doStop)
dbeReset  = apply(db, "Reset",doReset)

realize db

setCenteredSize(db, 1, 1)//H and W are set to 1 so user doesnt see the dialog box

inactive(dbeStart)

show db

When I first started this project I tried to have a infoBox or something of the such pop up once a time limit was reached but remembered that it halts all other functions until the user acknowledges it. So to kind of get around that I have a new dialog box display "YES" or "NO" (don't have a label in yet asking if they are still working or not...baby steps...) this allows the timer to continue to run in the background. If they click "YES" the timer would reset the db would close,  if they don't click anything or click "NO" the timer would stop, the db closes and the module would save and then close.


MrNiceGuy - Thu Jun 22 13:59:39 EDT 2017

Re: DXL Timer Question
MrNiceGuy - Thu Jun 22 14:03:48 EDT 2017

This is a side project btw im trying to do to help prevent users from locking other out of modules by leaving them open in exclusive.

Re: DXL Timer Question
Mathias Mamsch - Fri Jun 23 16:46:37 EDT 2017

MrNiceGuy - Thu Jun 22 14:03:48 EDT 2017

This is a side project btw im trying to do to help prevent users from locking other out of modules by leaving them open in exclusive.

I would rather take a look at the history from the timer and check if there have been any changes in the last X minutes. I would find it super annoying as a user to have such a script bothering me during work and I would close it right away. You will probably not resolve your problem by this. You might also be able to reach your goals differently, train the users or simply make it easy to message the person havin the module open. We had some similar posts here by the way. Use the search function. Regards, Mathias